//全选
$(function(){
    $("#zcheckbox").change(function(){//判断全选框的改变
        var flage =$(this).is(":checked");//全选选中为true，否则为false
        $("input[type=checkbox]").each(function(){
            $(this).prop("checked",flage);
        })
    })
});

//获取勾选的行数据的id并将其用,拼接成字符串
function getIds() {
    var str = '';
    for(var i = 0; i < document.getElementsByName('ids').length; i++) {
        if(document.getElementsByName('ids')[i].checked) {
            if(str == '') {
                str += document.getElementsByName('ids')[i].value;
            } else {
                str += ',' + document.getElementsByName('ids')[i].value;
            }
        }
    }
    return str;
}

//如果没有选择数据提示信息
function batchErrorMessage() {
    bootbox.dialog({
        message: "<span class='bigger-110'>您没有选择任何内容!</span>",
        buttons:{
            "button":{
                "label":"确定",
                "className":"btn-sm btn-success"
            }
        }
    });
    $("#zcheckbox").tips({
        side:3,
        msg:'点这里全选',
        bg:'#AE81FF',
        time:8
    });
}

//检索
function searchs(){
    top.jzts();
    $("#form").submit();
}

//查看详情
function detail(id) {
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title = "查看详情";
    diag.URL = path + '/admin/circleMemberInfo/detailPage?id='+ id;
    diag.Width = 1050;
    diag.Height = 550;
    diag.CancelEvent = function(){ //关闭事件
        diag.close();
    };
    diag.show();
}

//禁言或者取消禁言
function banOrNot(id, isBan, msg, currentPage) {
    var warning = "禁言后该圈员将不可在该圈子下继续发表文章！";
    var remind = "您确定要" + msg + "吗?";
    if (isBan == 1) { //想要禁言
        remind = warning + "<br/>" + remind;
    }
    bootbox.confirm(remind, function(result) {
        if(result) {
            top.jzts();
            var url = path +'/admin/circleMemberInfo/banOrNot?id=' + id + "&isBan=" + isBan;
            $.get(url,function(data){
                top.hangge();
                bootbox.dialog({
                    message: "<span class='bigger-110'>" + data.msg + "</span>",
                    buttons: {
                        "button":{
                            "label":"确定",
                            "className":"btn-sm btn-success",
                            "callback": function() {
                                nextPage(currentPage);
                            }
                        }
                    }
                });
            });
        };
    });
}

//新增
function add(currentPage){
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title ="新增";
    diag.URL = path + '/admin/circleMemberInfo/addPage';
    diag.Width = 1050;
    diag.Height = 580;
    diag.CancelEvent = function(){//关闭事件
        if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
            if(currentPage == '0'){
                top.jzts();
                setTimeout("self.location=self.location",100);
            }else{
                nextPage(currentPage);
            }
        }
        diag.close();
    };
    diag.show();
}

//编辑
function edit(id, currentPage){
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title ="编辑";
    diag.URL = path + '/admin/circleMemberInfo/editPage?id=' + id;
    diag.Width = 1050;
    diag.Height = 580;
    diag.CancelEvent = function(){//关闭事件
        if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
            if(currentPage == '0'){
                top.jzts();
                setTimeout("self.location=self.location",100);
            }else{
                nextPage(currentPage);
            }
        }
        diag.close();
    };
    diag.show();
}

//批量禁言
function batchBan(currentPage) {
    bootbox.confirm("确定要批量禁言选中的数据吗?", function(result) {
        if(result) {
            var ids = getIds();
            if(ids==''){
                batchErrorMessage();
            }else{
                top.jzts();
                $.ajax({
                    type: "POST",
                    url: path +'/admin/circleMemberInfo/batchBan',
                    data: {'ids' : ids},
                    dataType:'json',
                    cache: false,
                    success: function(data){
                        top.hangge();
                        bootbox.dialog({
                            message: "<span class='bigger-110'>"+data.msg+"</span>",
                            buttons: {
                                "button":{
                                    "label":"确定",
                                    "className":"btn-sm btn-success",
                                    "callback": function() {
                                        nextPage(currentPage);
                                    }
                                }
                            }
                        });
                    }
                });
            }
        }
    });
}

//批量取消禁言
function batchNotBan(currentPage) {
    bootbox.confirm("确定要批量取消禁言选中的数据吗?", function(result) {
        if(result) {
            var ids = getIds();
            if(ids==''){
                batchErrorMessage();
            }else{
                top.jzts();
                $.ajax({
                    type: "POST",
                    url: path +'/admin/circleMemberInfo/batchNotBan',
                    data: {'ids' : ids},
                    dataType:'json',
                    cache: false,
                    success: function(data){
                        top.hangge();
                        bootbox.dialog({
                            message: "<span class='bigger-110'>"+data.msg+"</span>",
                            buttons: {
                                "button":{
                                    "label":"确定",
                                    "className":"btn-sm btn-success",
                                    "callback": function() {
                                        nextPage(currentPage);
                                    }
                                }
                            }
                        });
                    }
                });
            }
        }
    });
}

